package inabit.inabitcompiler.productions.rule.expressions;

import inabit.compiler.parser.grammar.NonTerminal;
import inabit.compiler.parser.grammar.Production;
import inabit.compiler.parser.grammar.Symbol;
import inabit.data.expression.Expression;
import inabit.data.expression.LogicExpression;
import inabit.inabitcompiler.parser.InabitSemanticAction;

/**M -> KK'*/
/**@author Rafael Rocha*/
public class M_Rule extends Production{
	private NonTerminal K;
	private NonTerminal K1;
	public M_Rule() {
		super("M");
	}

	@Override
	protected Symbol[] production(final NonTerminal nonTerminal) {
		K = new NonTerminal("K");
		K1 = new NonTerminal("K'");
		Symbol[] symbols = {
				K,
				K1,
				new InabitSemanticAction(nonTerminal) {
					public void execute() {
						if(K1.code.isEmpty()) {
							nonTerminal.code = K.code;
						}else {
							Expression e = new LogicExpression(
									getExpression(K.code),
									LogicExpression.OR,
									getExpression(K1.code));
							
							nonTerminal.code = addExpressionAndGetCode(e);
						}
					}
				}
		};
		
		return symbols;
	}

}
